From 5a06dbaee41a37ae998996ddcfd9360d3c877767 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 23 Apr 2023 14:41:29 -0600 Subject: [PATCH] fix some readability-implict-bool-conversion tidy warnings (#1072) * fix some readability-implicit-bool-conversion warnings from clang-tidy * another implicit bool * fix tidy modernize-use-auto * fix google-readability-namespace-comments --- defs.h | 8 ++++---- discard.cc | 28 ++++++++++++++-------------- garmin_txt.cc | 36 ++++++++++++++++++------------------ igc.cc | 4 ++-- igc.h | 2 +- lowranceusr.cc | 2 +- lowranceusr.h | 2 +- main.cc | 12 ++++++------ src/core/codecdevice.cc | 2 +- src/core/codecdevice.h | 2 +- util.cc | 2 +- util_crc.cc | 2 +- waypt.cc | 2 +- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/defs.h b/defs.h index b01100b7e..f2e67f490 100644 --- a/defs.h +++ b/defs.h @@ -163,14 +163,14 @@ enum gpsdata_type { #define doing_posn ((global_opts.masked_objective & POSNDATAMASK) == POSNDATAMASK) struct global_options { - int synthesize_shortnames; int debug_level; gpsdata_type objective; unsigned int masked_objective; int verbose_status; /* set by GUI wrappers for status */ - int smart_icons; - int smart_names; inifile_t* inifile; + bool synthesize_shortnames; + bool smart_icons; + bool smart_names; }; extern global_options global_opts; @@ -535,7 +535,7 @@ void waypt_status_disp(int total_ct, int myct); //void waypt_disp_all(waypt_cb); /* template */ //void waypt_disp_session(const session_t* se, waypt_cb cb); /* template */ void waypt_init_bounds(bounds* bounds); -int waypt_bounds_valid(bounds* bounds); +bool waypt_bounds_valid(bounds* bounds); void waypt_add_to_bounds(bounds* bounds, const Waypoint* waypointp); void waypt_compute_bounds(bounds* bounds); Waypoint* find_waypt_by_name(const QString& name); diff --git a/discard.cc b/discard.cc index 7c55a5d9a..249d66a01 100644 --- a/discard.cc +++ b/discard.cc @@ -37,17 +37,17 @@ */ void DiscardFilter::fix_process_wpt(const Waypoint* wpt) { - int del = 0; - int delh = 0; - int delv = 0; + bool del = false; + bool delh = false; + bool delv = false; auto* waypointp = const_cast(wpt); if ((hdopf >= 0.0) && (waypointp->hdop > hdopf)) { - delh = 1; + delh = true; } if ((vdopf >= 0.0) && (waypointp->vdop > vdopf)) { - delv = 1; + delv = true; } if (andopt) { @@ -57,36 +57,36 @@ void DiscardFilter::fix_process_wpt(const Waypoint* wpt) } if ((satpf >= 0) && (waypointp->sat < satpf)) { - del = 1; + del = true; } if ((fixnoneopt) && (waypointp->fix == fix_none)) { - del = 1; + del = true; } if ((fixunknownopt) && (waypointp->fix == fix_unknown)) { - del = 1; + del = true; } if ((eleminopt) && (waypointp->altitude < eleminpf)) { - del = 1; + del = true; } if ((elemaxopt) && (waypointp->altitude > elemaxpf)) { - del = 1; + del = true; } if (nameopt && name_regex.match(waypointp->shortname).hasMatch()) { - del = 1; + del = true; } if (descopt && desc_regex.match(waypointp->description).hasMatch()) { - del = 1; + del = true; } if (cmtopt && cmt_regex.match(waypointp->notes).hasMatch()) { - del = 1; + del = true; } if (iconopt && icon_regex.match(waypointp->icon_descr).hasMatch()) { - del = 1; + del = true; } if (del) { diff --git a/garmin_txt.cc b/garmin_txt.cc index 415a48a81..9146aa6de 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -363,7 +363,7 @@ print_position(const Waypoint* wpt) } static void -print_date_and_time(const time_t time, const int time_only) +print_date_and_time(const time_t time, const bool time_only) { std::tm tm{}; char tbuf[32]; @@ -429,7 +429,7 @@ print_course(const Waypoint* A, const Waypoint* B) /* seems to be okay */ } static void -print_distance(const double distance, const int no_scale, const int with_tab, const int decis) +print_distance(const double distance, const bool no_scale, const bool with_tab, const int decis) { double dist = distance; @@ -561,19 +561,19 @@ write_waypt(const Waypoint* wpt) print_position(wpt); if IS_VALID_ALT(wpt->altitude) { - print_distance(wpt->altitude, 1, 0, 0); + print_distance(wpt->altitude, true, false, 0); } *fout << "\t"; double x = wpt->depth_value_or(unknown_alt); if (x != unknown_alt) { - print_distance(x, 1, 0, 1); + print_distance(x, true, false, 1); } *fout << "\t"; x = wpt->proximity_value_or(unknown_alt); if (x != unknown_alt) { - print_distance(x, 0, 0, 0); + print_distance(x, false, false, 0); } *fout << "\t"; @@ -596,7 +596,7 @@ write_waypt(const Waypoint* wpt) print_string("%s\t", garmin_fs_t::get_state(gmsd, "")); const char* country = gt_get_icao_country(garmin_fs_t::get_cc(gmsd, "")); print_string("%s\t", (country != nullptr) ? country : ""); - print_date_and_time(wpt->GetCreationTime().toTime_t(), 0); + print_date_and_time(wpt->GetCreationTime().toTime_t(), false); if (wpt->HasUrlLink()) { UrlLink l = wpt->GetUrlLink(); print_string("%s\t", l.url_); @@ -623,7 +623,7 @@ route_disp_hdr_cb(const route_head* rte) *fout << QString::asprintf("\r\n\r\nHeader\t%s\r\n", headers[route_header]); } print_string("\r\nRoute\t%s\t", rte->rte_name); - print_distance(cur_info->length, 0, 1, 0); + print_distance(cur_info->length, false, true, 0); print_course(cur_info->first_wpt, cur_info->last_wpt); *fout << QString::asprintf("\t%d waypoints\t", cur_info->count); if (rte->rte_urls.HasUrlLink()) { @@ -650,11 +650,11 @@ route_disp_wpt_cb(const Waypoint* wpt) if (prev != nullptr) { double dist = waypt_distance_ex(prev, wpt); cur_info->total += dist; - print_distance(cur_info->total, 0, 1, 0); - print_distance(dist, 0, 1, 0); + print_distance(cur_info->total, false, true, 0); + print_distance(dist, false, true, 0); print_course(prev, wpt); } else { - print_distance(0, 1, 0, 0); + print_distance(0, true, false, 0); } *fout << "\r\n"; @@ -677,9 +677,9 @@ track_disp_hdr_cb(const route_head* track) *fout << QString::asprintf("\r\n\r\nHeader\t%s\r\n", headers[track_header]); } print_string("\r\nTrack\t%s\t", track->rte_name); - print_date_and_time(cur_info->start, 0); - print_date_and_time(cur_info->time, 1); - print_distance(cur_info->length, 0, 1, 0); + print_date_and_time(cur_info->start, false); + print_date_and_time(cur_info->time, true); + print_distance(cur_info->length, false, true, 0); print_speed(&cur_info->length, &cur_info->time); if (track->rte_urls.HasUrlLink()) { print_string("%s", track->rte_urls.GetUrlLink().url_); @@ -705,15 +705,15 @@ track_disp_wpt_cb(const Waypoint* wpt) *fout << "Trackpoint\t"; print_position(wpt); - print_date_and_time(wpt->GetCreationTime().toTime_t(), 0); + print_date_and_time(wpt->GetCreationTime().toTime_t(), false); if IS_VALID_ALT(wpt->altitude) { - print_distance(wpt->altitude, 1, 0, 0); + print_distance(wpt->altitude, true, false, 0); } *fout << "\t"; double depth = wpt->depth_value_or(unknown_alt); if (depth != unknown_alt) { - print_distance(depth, 1, 0, 1); + print_distance(depth, true, false, 1); } if (prev != nullptr) { @@ -725,8 +725,8 @@ track_disp_wpt_cb(const Waypoint* wpt) } *fout << "\t"; dist = waypt_distance_ex(prev, wpt); - print_distance(dist, 0, 1, 0); - print_date_and_time(delta, 1); + print_distance(dist, false, true, 0); + print_date_and_time(delta, true); print_speed(&dist, &delta); print_course(prev, wpt); } diff --git a/igc.cc b/igc.cc index 3aeecabfa..1910f2915 100644 --- a/igc.cc +++ b/igc.cc @@ -69,9 +69,9 @@ * @retval 1 The coordinates are approximately equal * @retval 0 The coordinates are significantly different */ -unsigned char IgcFormat::coords_match(double lat1, double lon1, double lat2, double lon2) +bool IgcFormat::coords_match(double lat1, double lon1, double lat2, double lon2) { - return (fabs(lat1 - lat2) < 0.0001 && fabs(lon1 - lon2) < 0.0001) ? 1 : 0; + return (fabs(lat1 - lat2) < 0.0001 && fabs(lon1 - lon2) < 0.0001); } /************************************************************************************************* diff --git a/igc.h b/igc.h index dec27b12e..8646c1a10 100644 --- a/igc.h +++ b/igc.h @@ -236,7 +236,7 @@ private: /* Member Functions */ - static unsigned char coords_match(double, double, double, double); + static bool coords_match(double, double, double, double); igc_rec_type_t get_record(char**) const; void detect_pres_track(const route_head*); void detect_gnss_track(const route_head*); diff --git a/lowranceusr.cc b/lowranceusr.cc index 79b74587d..89a61585b 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -122,7 +122,7 @@ extern WaypointList* global_waypoint_list; /* below couple of functions mostly borrowed from raymarine.c */ /* make waypoint shortnames unique */ -char +bool LowranceusrFormat::same_points(const Waypoint* A, const Waypoint* B) { return ( /* !!! We are case-sensitive !!! */ diff --git a/lowranceusr.h b/lowranceusr.h index 605c12bd5..6013fdb27 100644 --- a/lowranceusr.h +++ b/lowranceusr.h @@ -384,7 +384,7 @@ private: /* Member Functions */ - static char same_points(const Waypoint*, const Waypoint*); + static bool same_points(const Waypoint*, const Waypoint*); void register_waypt(const Waypoint*) const; static const Waypoint* lowranceusr4_find_waypt(uint, int, int); static const Waypoint* lowranceusr4_find_global_waypt(uint, uint, uint, uint); diff --git a/main.cc b/main.cc index 6487ba604..3f5a08a91 100644 --- a/main.cc +++ b/main.cc @@ -55,7 +55,7 @@ #include "src/core/usasciicodec.h" // for UsAsciiCodec #include "vecs.h" // for Vecs -static constexpr int DEBUG_LOCALE = 0; +static constexpr bool DEBUG_LOCALE = false; #define MYNAME "main" // be careful not to advance argn passed the end of the list, i.e. ensure argn < qargs.size() @@ -414,7 +414,7 @@ run(const char* prog_name) } break; case 's': - global_opts.synthesize_shortnames = 1; + global_opts.synthesize_shortnames = true; break; case 't': global_opts.objective = trkdata; @@ -435,14 +435,14 @@ run(const char* prog_name) case 'S': switch (qargs.at(argn).size() > 2 ? qargs.at(argn).at(2).toLatin1() : '\0') { case 'i': - global_opts.smart_icons = 1; + global_opts.smart_icons = true; break; case 'n': - global_opts.smart_names = 1; + global_opts.smart_names = true; break; default: - global_opts.smart_icons = 1; - global_opts.smart_names = 1; + global_opts.smart_icons = true; + global_opts.smart_names = true; break; } break; diff --git a/src/core/codecdevice.cc b/src/core/codecdevice.cc index 77e322e45..de63389ef 100644 --- a/src/core/codecdevice.cc +++ b/src/core/codecdevice.cc @@ -154,4 +154,4 @@ bool CodecDevice::isSequential() const return true; } -} // namespace +} // namespace gpsbabel diff --git a/src/core/codecdevice.h b/src/core/codecdevice.h index 596bc2dcb..b1ef1b35a 100644 --- a/src/core/codecdevice.h +++ b/src/core/codecdevice.h @@ -62,5 +62,5 @@ private: qint64 charbuffer_bytes_free_{charbuffer_size_}; }; -} // namespace +} // namespace gpsbabel #endif // SRC_CORE_CODECDEVICE_H_ diff --git a/util.cc b/util.cc index e67b0bcaa..31ab466e0 100644 --- a/util.cc +++ b/util.cc @@ -146,7 +146,7 @@ xrealloc(void* p, size_t s) FILE* xfopen(const char* fname, const char* type, const char* errtxt) { - int am_writing = strchr(type, 'w') != nullptr; + bool am_writing = strchr(type, 'w') != nullptr; if (fname == nullptr) { fatal("%s must have a filename specified for %s.\n", diff --git a/util_crc.cc b/util_crc.cc index 640ceaba3..068d7db75 100644 --- a/util_crc.cc +++ b/util_crc.cc @@ -69,7 +69,7 @@ unsigned long get_crc32(const void* data, int datalen) { unsigned long crc = 0xFFFFFFFF; - const unsigned char* cp = static_cast(data); + const auto* cp = static_cast(data); while (cp < (static_cast(data) + datalen)) { crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *cp) &0xFF]; diff --git a/waypt.cc b/waypt.cc index df02d1715..39edfccc0 100644 --- a/waypt.cc +++ b/waypt.cc @@ -113,7 +113,7 @@ waypt_init_bounds(bounds* bounds) bounds->min_alt = -unknown_alt; } -int +bool waypt_bounds_valid(bounds* bounds) { /* Returns true if bb has any 'real' data in it */ -- 2.30.2